package com.ldatum.crm.util;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Scanner;

import com.ldatum.crm.domain.Thdetail;

public class CommonUtil {
	public static void sd(){
		Scanner sca=new Scanner(System.in);
		System.out.println("请输入存款年限：");
		double years=sca.nextDouble();
		sca.close();
		double base=7.7/100;
		double rate=base;
		double x = 3/(years-1);
		double y = 3/(float)(years-1);
		System.out.println("x:"+x+";y:"+y+":::::::"+(x-y));
		if(years==1){
			System.out.println("请输入整数");
		}else{
			if(years==1){
				rate *=0.5;
			}else if(years<=3){
				rate *=0.75;
			}else if(years<=5){
				rate=base;
			}else if(years>5){
				System.out.println("存期必须为5年或5年内");
			}else{
				System.out.println("实际利率："+rate);
			}
		}		
	}
	
	public static void isInteger(double args){
		String arg = args +"";
		for(int i =1;i<arg.length();i++){
			if(arg.substring(i-1, i).equals(".")){
				System.out.println("是小数");
				break;
			}
		}
	}
	//合并ID
	public static Integer combineId(Integer id1,Integer id2){
		if(id1==null && id2 == null){
			id1=id2=0;
		}
		if(id1==null){
			id1 = id2;
		}
		if(id2==null){
			id2 = id1;
		}
		return id1 & id2;
	}
	
	//科学计数法转换成double类型
	public static double convertToDouble(String args){
		BigDecimal bd = new BigDecimal(args);
		double d = Double.parseDouble(bd.toPlainString());
		return d;
	}
	//获取当前系统时间按照xxxx年xx月xx日 星期X
	public static String displaySystemTime(){
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH)+1;
		int day = cal.get(Calendar.DATE);
		int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
		String week = "";
		switch (dayOfWeek) {
		case 1:
			week = "日";
			break;
		case 2:
			week = "一";
			break;
		case 3:
			week = "二";
			break;
		case 4:
			week = "三";
			break;
		case 5:
			week = "四";
			break;
		case 6:
			week = "五";
			break;
		case 7:
			week = "六";
			break;
		default:
			break;
		}
		return "今天是"+year+"年"+month+"月"+day+"号  星期"+week;
	}
	
	
	public static void main(String[] args) {
		CommonUtil.isInteger(11.0);
	}

//	public static List<Sellerdetail> getSellerDetailByCart(String cart,String djh ) {
//		List<Sellerdetail> list = new ArrayList<Sellerdetail>();
//		String[] sellerDetail = cart.split(";");
//		for(String s:sellerDetail){
//			String[] detail =  s.split(",");
//			Sellerdetail sd = new Sellerdetail();
//			sd.setYpbm(detail[0]);
//			sd.setYpmc(detail[1]);
//			sd.setDj(Double.parseDouble(detail[2]));
//			sd.setXfsl(Integer.parseInt(detail[3]));
//			sd.setZhje(Double.parseDouble(detail[5]));
//			sd.setDjh(djh);
//			list.add(sd);
//		}
//		return list;
//	}

//	public static List<Jhdetail> getJhDetailByJhList(String jhList, String cgdjh) {
//		List<Jhdetail> list = new ArrayList<Jhdetail>();
//		String[] jhDetail = jhList.split(";");
//		for(String jh:jhDetail){
//			String[] detail =  jh.split(",");
//			Jhdetail jd = new Jhdetail();
//			jd.setPcm(detail[0]);
//			jd.setGys(detail[1]);
//			jd.setYpbm(detail[2]);
//			jd.setYpmc(detail[3]);
//			jd.setJhdm(detail[4]);
//			jd.setJhjg(Double.parseDouble(detail[5]));
//			jd.setJhsl(Integer.parseInt(detail[6]));
//			jd.setBz(detail[7]);
//			jd.setCgdbh(cgdjh);
//			list.add(jd);
//		}
//		return list;
//	}
	public static List<Thdetail> getThDetailByJhList(String thList, String thdjh) {
		List<Thdetail> list = new ArrayList<Thdetail>();
		String[] thDetail = thList.split(";");
		for(String jh:thDetail){
			String[] detail =  jh.split(",");
			Thdetail td = new Thdetail();
			td.setPcm(detail[0]);
			td.setYpbm(detail[1]);
			td.setYpmc(detail[2]);
			td.setThdm(detail[3]);
			td.setThjg(Double.parseDouble(detail[4]));
			td.setThsl(Integer.parseInt(detail[5]));
			td.setBz(detail[6]);
			td.setThdbh(thdjh);
			list.add(td);
		}
		return list;
	}
}
